package code13;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Homework02 {
	public static void main(String[] args) {
		Card[] cards = getCards();
//		for (Card card : cards) {
//			System.out.println(card);
//		}
		print3(cards);
	}
	/*
	 * 1.定义一个类, 表示一张纸牌, 需要有两个属性分别存储 一张牌的 花色、点数。
	 * 例如: 红桃3, 花色是 红桃, 点数是 3.
	 */
	
	/*
	 * 2.一副纸牌有 13(点数)*4(花色) + 2 王, 共 54张.
	 * 创建一个集合, 存储 54 张牌
	 */
	public static Card[] getCards() {
		Card[] cards = new Card[54];
		int index = 0;
		CardColor[] colors = CardColor.values();
		CardPoint[] points = CardPoint.values();
		int colorLength = colors.length - 1;// 不需要王
		int pointLength = points.length - 2;// 不需要王
		
		for (int i = 0; i < colorLength; i++) {
			for (int j = 0; j < pointLength; j++) {
				Card card = new Card(colors[i], points[j]);
				cards[index++] = card;
			}
		}
		// 单独处理 王
		cards[index++] = new Card(colors[colorLength], points[pointLength]);
		cards[index] = new Card(colors[colorLength], points[pointLength+1]);
		
		return cards;
	}
	
	/*
	 * 3.洗牌, 并把牌分成三份，并依次输出每一份的内容。
	 */
	public static void print3(Card[] cards) {
		List<Card> list = Arrays.asList(cards);
		// 随机排序(洗牌)
		Collections.shuffle(list);
		List<Card> player1 = new ArrayList<Card>();
		List<Card> player2 = new ArrayList<Card>();
		List<Card> player3 = new ArrayList<Card>();
		for (int i = 0; i < cards.length; i+=3) {
			player1.add(cards[i]);
			player2.add(cards[i+1]);
			player3.add(cards[i+2]);
		}
		System.out.println("输出:");
		System.out.println(player1.size() + "," + player2.size() + "," + player3.size());
		System.out.println(player1);
		System.out.println(player2);
		System.out.println(player3);
	}
	
}
class Card {
	public CardColor color;
	public CardPoint point;
	public Card(CardColor color, CardPoint point) {
		this.color = color;
		this.point = point;
	}
	@Override
	public String toString() {
		// 花色 + 点数
		if (color == CardColor.JOKERS) {
			return point.name + color.name;
		}
		return color.name + point.name;
	}
}
enum CardColor {
	HEARTS("红桃", 1),
	DIAMONDS("方块", 2),
	SPADES("黑桃", 3),
	CLUBS("梅花", 4),
	JOKERS("王", 5)
	;
	
	public String name;
	public int num;
	private CardColor(String name, int num) {
		this.name = name;
		this.num = num;
	}
}
enum CardPoint {
	CARD_A("A", 1),
	CARD_2("2", 2),
	CARD_3("3", 3),
	CARD_4("4", 4),
	CARD_5("5", 5),
	CARD_6("6", 6),
	CARD_7("7", 7),
	CARD_8("8", 8),
	CARD_9("9", 9),
	CARD_10("10", 10),
	CARD_J("J", 11),
	CARD_Q("Q", 12),
	CARD_K("K", 13),
	CARD_SMALL("小", 14),
	CARD_BIG("大", 15);
	
	public String name;
	public int num;
	private CardPoint(String name, int num) {
		this.name = name;
		this.num = num;
	}
}
